﻿// See https://aka.ms/new-console-template for more information
using ImageSkiaSharp;
using ShellProgressBar;

Console.WriteLine("Hello, World!");

//string yPath = "E:\\A_Work_Documents\\Projects\\58出海通\\门店信息原始图片\\未分类";
//string yPath = "E:\\A_Work_Documents\\Projects\\58出海通\\门店信息原始图片\\陈子康";
string yPath = "D:\\Documents\\A_Work_Documents\\Projects\\58出海通\\门店信息原始图片\\餐饮";

string newPath = Path.Combine(yPath,"ys"+new DateTime().ToLongDateString());

List<string> imgPaths = FileHelp.TraverseDirectory(yPath);

using (var pbar = new ProgressBar(imgPaths.Count, "正在压缩图片，请不要退出程序。", Progress.Options))
{
    var initialMessage = pbar.Message;
    int isNotImg = 0;
    for (int i = 0; i < imgPaths.Count; i++)
    {
        pbar.Message = $"Start {i + 1} of {imgPaths.Count} {Console.CursorTop}/{Console.WindowHeight}: {initialMessage}";
        FileHelp.CreateDirectory(newPath);
        if (imgPaths[i].Contains(".jpg") || imgPaths[i].Contains(".png"))
        {
            string savePath = Path.Combine(newPath, $"HSESEA-{Guid.NewGuid().ToString()}.jpg");
            ImageHelp.Compress(imgPaths[i], savePath, 1280, 50);

            if (i == imgPaths.Count - 1-isNotImg)
            {
                pbar.Tick($"End {i + 1} 已完成所有图片的压缩。");
            }
            else
            {
                pbar.Tick($"End {i + 1} of {imgPaths.Count} {Console.CursorTop}/{Console.WindowHeight}: {initialMessage}");
            }
        }
        else
        {
            isNotImg++;
            Console.WriteLine("以跳过非图片文件：" + imgPaths[i]);
        }
        
    }
}